package com.sunny.l51;

public class Solution {
    private TreeNode prev = null;
    private boolean res = true;
    public boolean isValidBST(TreeNode root) {
        if(null == root)
            return true;
        dfs(root);
        return res;
    }
    public void dfs(TreeNode node){
        if(null != node.left)
            dfs(node.left);
        if(null != prev && prev.val >= node.val){
            res = false;
            return;
        }
        prev = node;
        if(null != node.right)
            dfs(node.right);
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}